package 作业;

import java.util.Scanner;

public class ATM {
    public static void main(String[] args) {
    double balance = 0;
    boolean flag = true;
    Scanner scan = new Scanner(System.in);
        do{ System.out.println("==========ATM==========");
        System.out.println("==========1.存款==========");
        System.out.println("==========2.取款==========");
        System.out.println("==========3.显示余额==========");
        System.out.println("==========4.退出==========");
        System.out.println("==========请选择(1-4)==========");
        System.out.print("请选择1~4：");
        int res = scan.nextInt();
        switch (res) {
            case 1:
                System.out.println("请输入你要存款的金额：");
                double money1 = scan.nextDouble();
                if (money1>0) {
                    balance += money1;
                }else {
                    System.out.println("余额不足");
                }
                break;
            case 2:
                System.out.println("请输入你要取款的金额：");
                double money2 = scan.nextDouble();
                if(money2>0||money2<=balance){
                    balance -= money2;
                }else {
                    System.out.println("余额不足");
                }
                break;
            case 3:
                System.out.println("你的余额为："+balance);
                break;
            case 4:
                flag = false;
                System.out.println("感谢使用，欢迎下次再来");
                break;

            default:
                System.out.println("输入有误，请重新输入");
                break;

        }
    }while(flag);
        scan.close();


}
}
